// stores/user.js
import { defineStore } from 'pinia'
import { reactive, ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  const entry = ref('入口1')
  const classroom = ref(443)
  const mapInstance = ref(null)
  const map = ref(null)
  const position = ref([108.831906,34.125955])


  function setAim(newentry, newroom) {
    entry.value = newentry
    classroom.value = newroom
  }

  const setPosition = (newposition)=>{
    position.value = newposition
  }
  const setMapInstance = (map) => {//AMap
    mapInstance.value = map
  }
  const setMap = (newmap)=>{//map
    map.value = newmap
  }
  const destroyMap = () => {
    if (mapInstance.value) {
      mapInstance.value.destroy() // 调用高德地图的销毁方法
      mapInstance.value = null
    }
  }
    
  return { entry, classroom,mapInstance, map,position, setAim ,setMap,destroyMap,setPosition,setMapInstance}
})
